﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;
using System.Threading;
using RabbitMQ.Client;
using RabbitMQ.Client.Events;

namespace PoshRabbit
{
    [Cmdlet( VerbsCommon.New, "RabbitConsumer" )]
    public class NewConsumerCmdlet : RabbitCmdletBase
    {
        [Parameter(
            HelpMessage = "The name of the queue to create; if unspecified an anonymous queue will be created by the rabbit mq server",
            Mandatory = false,
            ValueFromPipelineByPropertyName = true
            )]
        [Alias("Q")]
        public string Queue { get; set; }

        [Parameter(
            HelpMessage = "The name of the consumer",
            Mandatory = true,
            ValueFromPipelineByPropertyName = true
            )]
        [ValidateNotNullOrEmpty]
        public string Name{ get; set; }

        protected override void ProcessRecord()
        {           
            var connector = new RabbitConnector(this);
            var consumer = new RabbitConsumer(connector, Queue, Name);
            consumer.Initialize();
            WriteObject(consumer);
        }
    }
}
